package com.datang.petstore.service.impl;
import com.datang.petstore.entity.ShareText;
import com.datang.petstore.entity.ShareTextExample;
import com.datang.petstore.generatemapper.ShareTextMapper;
import com.datang.petstore.service.ShareTextService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/*
 * @auther 顶风少年
 * @mail dfsn19970313@foxmail.com
 * @date 2019-11-04 10:15
 * @notify 分享语句
 * @version 1.0
 */

@Service
public class ShareTextServiceImpl implements ShareTextService {

    @Autowired
    private ShareTextMapper shareTextMapper;

    /*
     * @author 顶风少年
     * @date 2019/11/4 10:19
     * @mail dfsn199703132038@foxmail.com
     * @throws
     * @param
     * @result java.util.List<com.datang.petstore.entity.ShareText>
     * @notify 获取分享语句
     * version 1.0
     */
    @Cacheable(value = "getAllshareText",key="1")
    public List<ShareText> getAllshareText() {
        ShareTextExample shareTextExample = new ShareTextExample();
        List<ShareText> shareTexts = shareTextMapper.selectByExample(shareTextExample);
        return shareTexts;
    }

    /*
     * @author 顶风少年
     * @date 2019/11/19 17:04
     * @mail dfsn199703132038@foxmail.com
     * @throws
     * @param
     * @result java.util.List<com.datang.petstore.entity.InformCause>
     * @notify  添加分享语句
     * version 1.0
     */
    @CacheEvict(value = "getAllshareText",key="1" )
    @Transactional
    public void addShareText(ShareText shareText) {
        shareText.setDate(new Date());
        shareTextMapper.insert(shareText);
    }


    /*
     * @author 顶风少年
     * @date 2019/11/19 17:04
     * @mail dfsn199703132038@foxmail.com
     * @throws
     * @param
     * @result java.util.List<com.datang.petstore.entity.InformCause>
     * @notify 删除分享语句
     * version 1.0
     */
    @CacheEvict(value = "getAllshareText",key="1" )
    @Transactional
    public void deleteShareText(Integer id) {
        shareTextMapper.deleteByPrimaryKey(id);
    }

    /*
     * @author 顶风少年
     * @date 2019/11/19 17:04
     * @mail dfsn199703132038@foxmail.com
     * @throws
     * @param
     * @result java.util.List<com.datang.petstore.entity.InformCause>
     * @notify  更改分享语句
     * version 1.0
     */
    @CacheEvict(value = "getAllshareText",key="1" )
    @Transactional
    public void updateShareText(ShareText shareText) {
        shareText.setDate(new Date());
        shareTextMapper.updateByPrimaryKeySelective(shareText);
    }
}
